<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Creates new DateTimeZone object</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="class.datetimezone.html">DateTimeZone</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="datetimezone.getlocation.html">DateTimeZone::getLocation</a></div>
 <div class="up"><a href="class.datetimezone.html">DateTimeZone</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="datetimezone.construct" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">DateTimeZone::__construct</h1>
  <h1 class="refname">timezone_open</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.2.0)</p><p class="refpurpose"><span class="refname">DateTimeZone::__construct</span> -- <span class="refname">timezone_open</span> &mdash; <span class="dc-title">Creates new DateTimeZone object</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-datetimezone.construct-description">
  <h3 class="title">说明</h3>
  <p class="para">面向对象风格</p>
  <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>DateTimeZone::__construct()</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$timezone</code></span>
   )</div>

  <p class="para rdfs-comment">过程化风格</p>
  <div class="methodsynopsis dc-description">
   <span class="type"><a href="class.datetimezone.html" class="type DateTimeZone">DateTimeZone</a></span> <span class="methodname"><a href="function.timezone-open.html" class="methodname">timezone_open</a></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$timezone</code></span>
   )</div>

  <p class="para rdfs-comment">
   Creates new DateTimeZone object.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-datetimezone.construct-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">timezone</code></em></dt>

     <dd>

      <p class="para">
       One of <a href="timezones.html" class="link">timezones</a>.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-datetimezone.construct-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns <a href="class.datetimezone.html" class="classname">DateTimeZone</a> on success.
   过程化风格在失败时返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>

 
 <div class="refsect1 errors" id="refsect1-datetimezone.construct-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
   This method throws <a href="class.exception.html" class="classname">Exception</a> if the timezone supplied is not
   recognised as a valid timezone.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-datetimezone.construct-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2213">
    <p><strong>Example #1 Catching errors when instantiating <a href="class.datetimezone.html" class="classname">DateTimeZone</a></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Error&nbsp;handling&nbsp;by&nbsp;catching&nbsp;exceptions<br /></span><span style="color: #0000BB">$timezones&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'Europe/London'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'Mars/Phobos'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'Jupiter/Europa'</span><span style="color: #007700">);<br /><br />foreach&nbsp;(</span><span style="color: #0000BB">$timezones&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$tz</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$mars&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DateTimeZone</span><span style="color: #007700">(</span><span style="color: #0000BB">$tz</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch(</span><span style="color: #0000BB">Exception&nbsp;$e</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$e</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getMessage</span><span style="color: #007700">()&nbsp;.&nbsp;</span><span style="color: #DD0000">'&lt;br&nbsp;/&gt;'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
DateTimeZone::__construct() [datetimezone.--construct]: Unknown or bad timezone (Mars/Phobos)
DateTimeZone::__construct() [datetimezone.--construct]: Unknown or bad timezone (Jupiter/Europa)
</pre></div>
    </div>
   </div>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="class.datetimezone.html">DateTimeZone</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="datetimezone.getlocation.html">DateTimeZone::getLocation</a></div>
 <div class="up"><a href="class.datetimezone.html">DateTimeZone</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
